package com.qlyl.modules.information.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qlyl.common.api.vo.Result;
import com.qlyl.common.system.base.controller.JeecgController;
import com.qlyl.common.system.query.QueryGenerator;
import com.qlyl.modules.information.entity.Consumers;
import com.qlyl.modules.information.entity.EthTransaction;
import com.qlyl.modules.information.service.IConsumersService;
import com.qlyl.modules.information.service.IEthTransactionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RequestMapping("/ethTransaction")
@RestController
public class EthTransactionController extends JeecgController<EthTransaction, IEthTransactionService> {

    @Autowired
    private IEthTransactionService ethTransactionService;


    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result<IPage<EthTransaction>> queryPageList(EthTransaction ethTransaction, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
        Result<IPage<EthTransaction>> result = new Result<IPage<EthTransaction>>();
        QueryWrapper<EthTransaction> queryWrapper = QueryGenerator.initQueryWrapper(ethTransaction, req.getParameterMap());

        Page<EthTransaction> page = new Page<EthTransaction>(pageNo, pageSize);
        IPage<EthTransaction> pageList = ethTransactionService.page(page, queryWrapper);

        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    @GetMapping("/list_by_user_id")
    public Result<IPage<EthTransaction>> queryByUserId(@RequestParam(name = "userId", required=false) String userId,
                                                       @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Result<IPage<EthTransaction>> result = new Result<IPage<EthTransaction>>();
        Page<EthTransaction> page = new Page<EthTransaction>(pageNo, pageSize);
        IPage<EthTransaction> pageList = ethTransactionService.selectAndConsumers(page, userId);

        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }



    /**
     * 导出excel
     * @param ethTransaction
     * @param request
     */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(EthTransaction ethTransaction, HttpServletRequest request) {

        return exportXls(request,ethTransaction,EthTransaction.class,"上链信息列表");

    }


}
